// subpkg/rooms/rooms.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    src: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.gCeS6pGusV61ZBuKp4zaMgHaDp?w=343&h=172&c=7&r=0&o=5&dpr=1.25&pid=1.7',
    src02: 'https://dimg20.c-ctrip.com/images/70030n000000e34vwB318.jpg',
    src03: 'https://dimg04.c-ctrip.com/images/700o1a0000018ybax5DBF.jpg',
    date: '',
    showDate: false,
    showPer: false,
    numPer: '1',
    numRoom: '1',
    valueNumber: '1间--1人'
  },
  onChangePage() {
    if (this.data.date == '') {
      wx.showToast({
        title: "请选择日期",
        icon: "none"
      })
    } else {
      app.navigateTo('./list/list?date=' + this.data.date + '&numPer=' + this.data.numPer + '&numRoom=' + this.data.numRoom, true)
    }
  },
  // 修改选择日期弹窗状态函数
  onDisplay() {
    this.setData({
      showDate: true
    });
  },
  onCloseDate() {
    this.setData({
      showDate: false
    });
  },
  formatDate(date) {
    date = new Date(date);
    return `${date.getMonth() + 1}/${date.getDate()}`;
  },
  // 确认后将选择日期渲染到页面上
  onConfirm(event) {
    const [start, end] = event.detail;
    this.setData({
      showDate: false,
      'date': `${this.formatDate(start)} - ${this.formatDate(end)}`,
    });
  },
  // 控制选择人数弹窗的显示状态
  showPopup() {
    this.setData({
      showPer: true
    });
  },
  onClose() {
    this.setData({
      showPer: false
    });
  },
  // 分别修改data里numRoom和numPer的值
  onChangeRoom(e) {
    // console.log(e.detail);
    // console.log(this.data);
    this.setData({
      'numRoom': e.detail
    })
  },
  onChangePer(e) {
    // console.log(e.detail)
    this.setData({
      'numPer': e.detail
    })
  },

  onConfirmNumber: function (e) {
    // console.log(this.data)
    let a = this.data;
    this.setData({
      showPer: false,
      valueNumber: a.numRoom + '间--' + a.numPer + '人'
    })
  }

})